using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Commerce.Common{
    /// <summary>
    /// Strongly-typed collection for the VCoupon class.
    /// </summary>
    [Serializable]
    public partial class VCouponCollection : ReadOnlyList<VCoupon, VCouponCollection>
    {        
        public VCouponCollection() {}

    }

    /// <summary>
    /// This is  Read-only wrapper class for the vCoupons view.
    /// </summary>
    [Serializable]
    public partial class VCoupon : ReadOnlyRecord<VCoupon>, IReadOnlyRecord
    {
    
	    #region Default Settings
	    protected static void SetSQLProps() 
	    {
		    GetTableSchema();
	    }

	    #endregion
        #region Schema Accessor
	    public static TableSchema.Table Schema
        {
            get
            {
                if (BaseSchema == null)
                {
                    SetSQLProps();
                }

                return BaseSchema;
            }

        }

    	
        private static void GetTableSchema() 
        {
            if(!IsSchemaInitialized)
            {
                //Schema declaration
                TableSchema.Table schema = new TableSchema.Table("vCoupons", TableType.View, DataService.GetInstance("dashCommerce"));
                schema.Columns = new TableSchema.TableColumnCollection();
                schema.SchemaName = "dbo";
                //columns
                
                TableSchema.TableColumn colvarCouponCode = new TableSchema.TableColumn(schema);
                colvarCouponCode.ColumnName = "CouponCode";
                colvarCouponCode.DataType = DbType.String;
                colvarCouponCode.MaxLength = 30;
                colvarCouponCode.AutoIncrement = false;
                colvarCouponCode.IsNullable = false;
                colvarCouponCode.IsPrimaryKey = false;
                colvarCouponCode.IsForeignKey = false;
                colvarCouponCode.IsReadOnly = false;
                
                schema.Columns.Add(colvarCouponCode);
                
                TableSchema.TableColumn colvarCouponTypeId = new TableSchema.TableColumn(schema);
                colvarCouponTypeId.ColumnName = "CouponTypeId";
                colvarCouponTypeId.DataType = DbType.Int32;
                colvarCouponTypeId.MaxLength = 0;
                colvarCouponTypeId.AutoIncrement = false;
                colvarCouponTypeId.IsNullable = false;
                colvarCouponTypeId.IsPrimaryKey = false;
                colvarCouponTypeId.IsForeignKey = false;
                colvarCouponTypeId.IsReadOnly = false;
                
                schema.Columns.Add(colvarCouponTypeId);
                
                TableSchema.TableColumn colvarIsSingleUse = new TableSchema.TableColumn(schema);
                colvarIsSingleUse.ColumnName = "IsSingleUse";
                colvarIsSingleUse.DataType = DbType.Boolean;
                colvarIsSingleUse.MaxLength = 0;
                colvarIsSingleUse.AutoIncrement = false;
                colvarIsSingleUse.IsNullable = false;
                colvarIsSingleUse.IsPrimaryKey = false;
                colvarIsSingleUse.IsForeignKey = false;
                colvarIsSingleUse.IsReadOnly = false;
                
                schema.Columns.Add(colvarIsSingleUse);
                
                TableSchema.TableColumn colvarCouponType = new TableSchema.TableColumn(schema);
                colvarCouponType.ColumnName = "CouponType";
                colvarCouponType.DataType = DbType.String;
                colvarCouponType.MaxLength = 128;
                colvarCouponType.AutoIncrement = false;
                colvarCouponType.IsNullable = false;
                colvarCouponType.IsPrimaryKey = false;
                colvarCouponType.IsForeignKey = false;
                colvarCouponType.IsReadOnly = false;
                
                schema.Columns.Add(colvarCouponType);
                
                TableSchema.TableColumn colvarCouponClassType = new TableSchema.TableColumn(schema);
                colvarCouponClassType.ColumnName = "CouponClassType";
                colvarCouponClassType.DataType = DbType.String;
                colvarCouponClassType.MaxLength = 256;
                colvarCouponClassType.AutoIncrement = false;
                colvarCouponClassType.IsNullable = false;
                colvarCouponClassType.IsPrimaryKey = false;
                colvarCouponClassType.IsForeignKey = false;
                colvarCouponClassType.IsReadOnly = false;
                
                schema.Columns.Add(colvarCouponClassType);
                
                TableSchema.TableColumn colvarIsAspClass = new TableSchema.TableColumn(schema);
                colvarIsAspClass.ColumnName = "IsAspClass";
                colvarIsAspClass.DataType = DbType.Boolean;
                colvarIsAspClass.MaxLength = 0;
                colvarIsAspClass.AutoIncrement = false;
                colvarIsAspClass.IsNullable = false;
                colvarIsAspClass.IsPrimaryKey = false;
                colvarIsAspClass.IsForeignKey = false;
                colvarIsAspClass.IsReadOnly = false;
                
                schema.Columns.Add(colvarIsAspClass);
                
                TableSchema.TableColumn colvarNumberOfUses = new TableSchema.TableColumn(schema);
                colvarNumberOfUses.ColumnName = "NumberOfUses";
                colvarNumberOfUses.DataType = DbType.Int32;
                colvarNumberOfUses.MaxLength = 0;
                colvarNumberOfUses.AutoIncrement = false;
                colvarNumberOfUses.IsNullable = false;
                colvarNumberOfUses.IsPrimaryKey = false;
                colvarNumberOfUses.IsForeignKey = false;
                colvarNumberOfUses.IsReadOnly = false;
                
                schema.Columns.Add(colvarNumberOfUses);
                
                TableSchema.TableColumn colvarExpirationDate = new TableSchema.TableColumn(schema);
                colvarExpirationDate.ColumnName = "ExpirationDate";
                colvarExpirationDate.DataType = DbType.DateTime;
                colvarExpirationDate.MaxLength = 0;
                colvarExpirationDate.AutoIncrement = false;
                colvarExpirationDate.IsNullable = true;
                colvarExpirationDate.IsPrimaryKey = false;
                colvarExpirationDate.IsForeignKey = false;
                colvarExpirationDate.IsReadOnly = false;
                
                schema.Columns.Add(colvarExpirationDate);
                
                TableSchema.TableColumn colvarXmlData = new TableSchema.TableColumn(schema);
                colvarXmlData.ColumnName = "XmlData";
                colvarXmlData.DataType = DbType.String;
                colvarXmlData.MaxLength = 1073741823;
                colvarXmlData.AutoIncrement = false;
                colvarXmlData.IsNullable = false;
                colvarXmlData.IsPrimaryKey = false;
                colvarXmlData.IsForeignKey = false;
                colvarXmlData.IsReadOnly = false;
                
                schema.Columns.Add(colvarXmlData);
                
                TableSchema.TableColumn colvarUserId = new TableSchema.TableColumn(schema);
                colvarUserId.ColumnName = "UserId";
                colvarUserId.DataType = DbType.Guid;
                colvarUserId.MaxLength = 0;
                colvarUserId.AutoIncrement = false;
                colvarUserId.IsNullable = true;
                colvarUserId.IsPrimaryKey = false;
                colvarUserId.IsForeignKey = false;
                colvarUserId.IsReadOnly = false;
                
                schema.Columns.Add(colvarUserId);
                
                
                BaseSchema = schema;
                //add this schema to the provider
                //so we can query it later
                DataService.Providers["dashCommerce"].AddSchema("vCoupons",schema);
            }

        }

        #endregion
        
        #region Query Accessor
	    public static Query CreateQuery()
	    {
		    return new Query(Schema);
	    }

	    #endregion
	    
	    #region .ctors
	    public VCoupon()
	    {
            SetSQLProps();
            SetDefaults();
            MarkNew();
        }

        public VCoupon(bool useDatabaseDefaults)
	    {
		    SetSQLProps();
		    if(useDatabaseDefaults)
		    {
				ForceDefaults();
			}

			MarkNew();
	    }

	    
	    public VCoupon(object keyID)
	    {
		    SetSQLProps();
		    LoadByKey(keyID);
	    }

    	 
	    public VCoupon(string columnName, object columnValue)
        {
            SetSQLProps();
            LoadByParam(columnName,columnValue);
        }

        
	    #endregion
	    
	    #region Props
	    
          
        [XmlAttribute("CouponCode")]
        public string CouponCode 
	    {
		    get
		    {
			    return GetColumnValue<string>("CouponCode");
		    }

            set 
		    {
			    SetColumnValue("CouponCode", value);
            }

        }

	      
        [XmlAttribute("CouponTypeId")]
        public int CouponTypeId 
	    {
		    get
		    {
			    return GetColumnValue<int>("CouponTypeId");
		    }

            set 
		    {
			    SetColumnValue("CouponTypeId", value);
            }

        }

	      
        [XmlAttribute("IsSingleUse")]
        public bool IsSingleUse 
	    {
		    get
		    {
			    return GetColumnValue<bool>("IsSingleUse");
		    }

            set 
		    {
			    SetColumnValue("IsSingleUse", value);
            }

        }

	      
        [XmlAttribute("CouponType")]
        public string CouponType 
	    {
		    get
		    {
			    return GetColumnValue<string>("CouponType");
		    }

            set 
		    {
			    SetColumnValue("CouponType", value);
            }

        }

	      
        [XmlAttribute("CouponClassType")]
        public string CouponClassType 
	    {
		    get
		    {
			    return GetColumnValue<string>("CouponClassType");
		    }

            set 
		    {
			    SetColumnValue("CouponClassType", value);
            }

        }

	      
        [XmlAttribute("IsAspClass")]
        public bool IsAspClass 
	    {
		    get
		    {
			    return GetColumnValue<bool>("IsAspClass");
		    }

            set 
		    {
			    SetColumnValue("IsAspClass", value);
            }

        }

	      
        [XmlAttribute("NumberOfUses")]
        public int NumberOfUses 
	    {
		    get
		    {
			    return GetColumnValue<int>("NumberOfUses");
		    }

            set 
		    {
			    SetColumnValue("NumberOfUses", value);
            }

        }

	      
        [XmlAttribute("ExpirationDate")]
        public DateTime? ExpirationDate 
	    {
		    get
		    {
			    return GetColumnValue<DateTime?>("ExpirationDate");
		    }

            set 
		    {
			    SetColumnValue("ExpirationDate", value);
            }

        }

	      
        [XmlAttribute("XmlData")]
        public string XmlData 
	    {
		    get
		    {
			    return GetColumnValue<string>("XmlData");
		    }

            set 
		    {
			    SetColumnValue("XmlData", value);
            }

        }

	      
        [XmlAttribute("UserId")]
        public Guid? UserId 
	    {
		    get
		    {
			    return GetColumnValue<Guid?>("UserId");
		    }

            set 
		    {
			    SetColumnValue("UserId", value);
            }

        }

	    
	    #endregion
    
	    #region Columns Struct
	    public struct Columns
	    {
		    
		    
            public static string CouponCode = @"CouponCode";
            
            public static string CouponTypeId = @"CouponTypeId";
            
            public static string IsSingleUse = @"IsSingleUse";
            
            public static string CouponType = @"CouponType";
            
            public static string CouponClassType = @"CouponClassType";
            
            public static string IsAspClass = @"IsAspClass";
            
            public static string NumberOfUses = @"NumberOfUses";
            
            public static string ExpirationDate = @"ExpirationDate";
            
            public static string XmlData = @"XmlData";
            
            public static string UserId = @"UserId";
            
	    }

	    #endregion
	    
	    
	    #region IAbstractRecord Members
        public new CT GetColumnValue<CT>(string columnName) {
            return base.GetColumnValue<CT>(columnName);
        }

        public object GetColumnValue(string columnName) {
            return base.GetColumnValue<object>(columnName);
        }

        #endregion
	    
    }

}

